(function($){
	$.ToolBarButtonListen = function (arg) {
        this.init =function () {
        	var item=arg.item;
        	var gridDateId=item+'_list_id';//表格id
        	var editWinId=item+'_win_edit_id';//增加修改窗口
        	var editWinFooter=item+'_win_edit_footer_id'//窗口工具栏按钮
        	var toolbarId=item+'_list_toolbar_id';//工具栏id
        	var editForm=item+'EditForm';//表单id
        	var haswin=false;
        	$('#'+toolbarId).children("a[type='oper']").each(function(){
        		var operator=$(this).attr("operator");
        		var title=$(this).attr("title");
        		var url=$(this).attr("url");
        		if(operator=="add" || operator=="edit"){
        			haswin=true;//打开了窗口
        		}
        		//按钮被禁用不执行
        		if(!$(this).hasClass("l-btn-disabled")){
        			
        			//工具栏 添加按钮
        			if(operator=="add"){
        				$(this).click(function(){
        					var isclick=true;
        					if(arg.requiredTree){
        						var nod=$("#"+arg.treeId).tree('getSelected');
        						if(!nod){
        							showInfo(arg.treeEmpty);
        							isclick=false;
        						}
        					}
        					if(isclick){
        						$('#'+editWinId).window('open');
            					$('#'+editWinId).panel({
            						title:title
            					});
            					var nurl= parseUrl(url);
            					$('#'+editWinId).window('refresh',nurl);
        					}
        					
        				})
        			}
        			//工具栏编辑按钮
        			if(operator=="edit"){
        				$(this).click(function(){
        					var row = $('#'+gridDateId).datagrid('getChecked');
        					if (row.length==0){
//        						$.messager.alert('Warning',"请选中要编辑的行");
        						showInfo("请选中要编辑的行");
        					}else if(row.length>1){
        						showInfo("每次编辑最多只能选一行");
//        						$.messager.alert('Warning',"每次编辑最多只能选一行");
        					}else{
        						$('#'+editWinId).window('open');
        						$('#'+editWinId).panel({title:title});
        						var nurl= parseUrl(url,row[0].id);
        						$('#'+editWinId).window('refresh', nurl);
        					}
        				})
        			}
        			//工具栏删除按钮
        			if(operator=="del"){
        				$(this).click(function(){
        					var row = $('#'+gridDateId).datagrid('getChecked');
        					if(row.length>0){
        						var ids=new Array();
        						for(var i=0;i<row.length;i++){
        							ids.push(row[i].id);
        						}
        						var pstr=JSON.stringify(ids);
        						$.messager.confirm('Confirm','确定要删除选择的行吗?',function(r){
        							if(r){
        								$.ajax({
        						            type: "GET",
        						            url: url,
        						            data: {ids:pstr},
        						            dataType: "json",
        						            success: function(data){
        						            	if(data.success){
        						            		showSuccessMsg("删除成功,请到回收站查看");
        						            		loadDataGrid(gridDateId);
        						            		if(arg.treeId!=null && arg.treeId!=''){
        	            								$("#"+arg.treeId).tree('reload');
        	            							}
        						            	}else{
//        						            		$.messager.alert('Warning',data.msg);
        						            		showMsg(data.msg);
        						            	}
        						            }
        						        });
        							}
        						});
        					}else{
//        						$.messager.alert('Warning',"请选中要删除的行");
        						showInfo("请选中要删除的行");
        					}
        				})
        			}
        			//资源分配
        			if(operator=="res"){
        				$(this).click(function(){
        					var row = $('#'+gridDateId).datagrid('getChecked');
        					if (row.length==0){
        						showInfo("请选中要分配的角色");
//        						$.messager.alert('Warning',"请选中要分配的角色");
        					}else if(row.length>1){
        						showInfo("每次分配最多只能选一行");
//        						$.messager.alert('Warning',"每次分配最多只能选一行");
        					}else{
        						var nurl= parseUrl(url,row[0].id);
        						$('#allotResourceId').window('open');
        						$('#allotResourceId').window('refresh', nurl);
        					}
        				})
        			}
        			//角色分派
        			if(operator=="role"){
        				$(this).click(function(){
        					var row = $('#'+gridDateId).datagrid('getChecked');
        					if (row.length==0){
        						showInfo("请选中要分配的员工");
        					}else if(row.length>1){
        						showInfo("每次分配最多只能选一行");
        					}else{
        						var nurl= parseUrl(url,row[0].id);
        						$('#allotRoleId').window('open');
        						$('#allotRoleId').window('refresh', nurl);
        					}
        				})
        			}
        			//设置领导
        			if(operator=="sleader"){
        				$(this).click(function(){
        					var isclick=true;
        					if(arg.requiredTree){
        						var nod=$("#"+arg.treeId).tree('getSelected');
        						if(!nod){
        							showInfo(arg.treeEmpty);
        							isclick=false;
        						}
        					}
        					if(isclick){
        						var row = $('#'+gridDateId).datagrid('getChecked');
            					if (row.length==0){
            						showInfo("请选中要设置的员工");
            					}else if(row.length>1){
            						showInfo("每次设置最多只能选一行");
            					}else{
            						var nurl= parseUrl(url,row[0].id);
            						$.messager.confirm('Confirm','确定要设置此人为领导吗?',function(r){
            							if(r){
            								$.ajax({
            						            type: "GET",
            						            url: nurl,
            						            dataType: "json",
            						            success: function(data){
            						            	if(data.success){
            						            		showSuccessMsg("设置成功");
            						            		loadDataGrid(gridDateId);
            						            	}else{
            						            		showMsg(data.msg);
            						            	}
            						            }
            						        });
            							}
            						});
            					}
        					}
        				})
        			}
        			//回收站
        			if(operator=="trash"){
        				$(this).click(function(){
        					$('#recycleId').window('open');
        					var nurl= parseUrl(url);
        					$('#recycleId').window('refresh', nurl);
        				})
        			}
        			
        			if(operator=="refresh"){
        				$(this).click(function(){
        					loadDataGrid(gridDateId);
        				})
        			}
        			
        			if(operator=="contact"){
        				$(this).click(function(){
        					var row = $('#'+gridDateId).datagrid('getChecked');
        					if (row.length==0){
        						showInfo("请选中要查看的员工");
        					}else if(row.length>1){
        						showInfo("每次最多只能选一行");
        					}else{
        						var nurl= parseUrl(url,row[0].id);
        						$('#contact_photo_id').window('open');
        						$('#contact_photo_id').window('refresh', nurl);
        					}
        				})
        			}
        			
        			//工具栏 添加按钮
        			if(operator=="detail"){
        				$(this).click(function(){
        					var row = $('#'+gridDateId).datagrid('getChecked');
        					if (row.length==0){
        						showInfo("请选中要查看的行");
        					}else if(row.length>1){
        						showInfo("每次最多只能选一行");
        					}else{
        						$('#'+arg.detailwin).window('open');
            					var nurl= parseUrl(url,row[0].id);
            					$('#'+arg.detailwin).window('refresh',nurl);
        					}
        				})
        			}
        		}
        	});

        	if(haswin){
            	$('#'+editWinFooter).children("a[type='save']").click(function(){
            		var saveurl=$('#'+editForm).attr("target");
            		//新增窗口保存方法
            		$('#'+editForm).form(
            				'submit',
            				{
            					url : saveurl,
            					onSubmit : function(param) {
            					},
            					success : function(data) {
            						var obj = $.parseJSON(data);
            						if (obj.success) {
            							showSuccessMsg("操作成功！");
            							closeFun(editWinId,editForm,gridDateId)
            							loadDataGrid(gridDateId);
            						} else {
            							showMsg(obj.msg);
            						}
            					}
            				});
            	});
            	
            	//关闭窗口的方法
            	$('#'+editWinFooter).children("a[type='close']").click(function(){
            		closeFun(editWinId,editForm,gridDateId)
            	});
        	}
        };
        //表格加载
        this.gridData=function(){
        	var item=arg.item;
        	var gridDateId=item+'_list_id';//表格id
        	 $('#'+gridDateId).datagrid({
				 url:arg.gridUrl,
				 queryParams: {param:getParams(arg.treeFeildId)}
			 }); //指定列;
        };
        //树加载
        this.treeData=function(){
        	var item=arg.item;
        	var gridDateId=item+'_list_id';//表格id
        	$("#"+arg.treeId).tree({
		        url : arg.treeUrl,
		        animate:true,
		        onClick : function(node) {
		        	setSearchHidden(arg.treeFeildId,node.id);
					setGenelHidden(arg.treeFeildName,node.text);
					if(item=='user'){
						setGenelHidden('leader',node.leader);
					}
					loadDataGrid(gridDateId,arg.treeFeildId);
		        }
        	});
        };
    };
    $.ToolBarRecycle = function (arg) {
    	 this.init =function () {
    		 var item=arg.item;
    		 var toolbarId=item+'_list_recycle_toolbar_id';//工具栏id
         	var gridDateId=item+'_recycle_id';//表格id
         	var parentGrid=item+'_list_id';
         	
         	$('#'+toolbarId).children("a[type='oper']").each(function(){
         		var operator=$(this).attr("operator");
         		var title=$(this).attr("title");
         		var url=$(this).attr("url");
         		//按钮被禁用不执行
         		if(!$(this).hasClass("l-btn-disabled")){
         			//找回
         			if(operator=="recover"){
         				$(this).click(function(){
         					var row = $('#'+gridDateId).datagrid('getChecked');
         					if(row.length>0){
         						var ids=new Array();
         						for(var i=0;i<row.length;i++){
         							ids.push(row[i].id);
         						}
         						var pstr=JSON.stringify(ids);
         						$.messager.confirm('Confirm','确定要恢复选择的行吗?恢复不完整，其他关联可能丢失',function(r){
         							if(r){
         								$.ajax({
         						            type: "GET",
         						            url: url,
         						            data: {ids:pstr},
         						            dataType: "json",
         						            success: function(data){
         						            	if(data.success){
         						            		showSuccessMsg("恢复成功，请到列表查看");
         						            		loadDataGrid(gridDateId);
         						            		loadDataGrid(parentGrid);
         						            		if(arg.treeId!=null && arg.treeId!=''){
         	            								$("#"+arg.treeId).tree('reload');
         	            							}
         						            	}else{
         						            		showMsg(data.msg);
//         						            		$.messager.alert('Warning',data.msg);
         						            	}
         						            }
         						        });
         							}
         						});
         					}else{
//         						$.messager.alert('Warning',"请选中要恢复的行");
         						showInfo("请选中要恢复的行");
         					}
         				})
         			}
         			//情况
         			if(operator=="empty"){
         				$(this).click(function(){
         					$.messager.confirm('Confirm','确定要清空回收站吗？清空不可逆,请谨慎操作',function(r){
     							if(r){
     								$.ajax({
     						            type: "GET",
     						            url: url,
     						            dataType: "json",
     						            success: function(data){
     						            	if(data.success){
     						            		showSuccessMsg("清空成功");
     						            		loadDataGrid(gridDateId);
     						            	}else{
//     						            		$.messager.alert('Warning',data.msg);
     						            		showMsg(data.msg);
     						            	}
     						            }
     						        });
     							}
     						});
         				})
         			}
         			//情况
         			if(operator=="remove"){
         				$(this).click(function(){
         					var row = $('#'+gridDateId).datagrid('getChecked');
         					if(row.length>0){
         						var ids=new Array();
         						for(var i=0;i<row.length;i++){
         							ids.push(row[i].id);
         						}
         						var pstr=JSON.stringify(ids);
         						$.messager.confirm('Confirm','确定要删除选择的行吗?删除不可逆,请谨慎操作',function(r){
         							if(r){
         								$.ajax({
         						            type: "GET",
         						            url: url,
         						            data: {ids:pstr},
         						            dataType: "json",
         						            success: function(data){
         						            	if(data.success){
         						            		showSuccessMsg("删除成功");
         						            		loadDataGrid(gridDateId);
         						            	}else{
//         						            		$.messager.alert('Warning',data.msg);
         						            		showMsg(data.msg);
         						            	}
         						            }
         						        });
         							}
         						});
         					}else{
//         						$.messager.alert('Warning',"请选中要删除的行");
         						showInfo("请选中要删除的行");
         					}
         				})
         			}
         		}
         	});
         };
    };
    
    $.ToolBarRowClick = function (arg) {
    	 this.init =function () {
    		 var parentTable=arg.parentTable+"_list_id";
    		 var toolbarId=arg.item+'_list_toolbar_id';//工具栏id
    		 var childGrid=arg.item+"_list_id";
 			$('#'+parentTable).datagrid({
 				onClickRow:function(rowIndex,rowData){
 					$('#'+childGrid).datagrid({
 						url:arg.gridUrl,
 						queryParams: {id:rowData.id}
 					})
 				}
 			});
 			
 			$('#'+toolbarId).children("a[type='oper']").each(function(){
        		var operator=$(this).attr("operator");
        		var title=$(this).attr("title");
        		var url=$(this).attr("url");
        		//按钮被禁用不执行
        		if(!$(this).hasClass("l-btn-disabled")){
        			//工具栏 添加按钮
        			if(operator=="allotjob"){
        				$(this).click(function(){
        					var row = $('#'+parentTable).datagrid('getSelected');
        					if (row){
        						var nurl= url+'?userId='+row.id;
        						$('#allotJobId').window('open');
        						$('#allotJobId').window('refresh', nurl);
        					}else{
//        						$.messager.alert('Warning',"请选择要分配的员工");
        						showInfo("请选择要分配的员工");
        					}
        				})
        			}
        			if(operator=="deljob"){
        				$(this).click(function(){
        					var row = $('#'+childGrid).datagrid('getChecked');
        					if(row.length>0){
        						var ids=new Array();
        						for(var i=0;i<row.length;i++){
        							ids.push(row[i].id);
        						}
        						var pstr=JSON.stringify(ids);
        						$.messager.confirm('Confirm','确定要删除选择的行吗?',function(r){
        							if(r){
        								$.ajax({
        						            type: "GET",
        						            url: url,
        						            data: {ids:pstr},
        						            dataType: "json",
        						            success: function(data){
        						            	if(data.success){
        						            		showSuccessMsg("删除成功");
        						            		loadDataGrid(childGrid);
        						            	}else{
//        						            		$.messager.alert('Warning',data.msg);
        						            		showMsg(data.msg);
        						            	}
        						            }
        						        });
        							}
        						});
        					}else{
//        						$.messager.alert('Warning',"请选中要删除的行");
        						showInfo("请选中要删除的行");
        					}
        				})
        			}
        			if(operator=="majoyJob"){
        				$(this).click(function(){
        					var row = $('#'+childGrid).datagrid('getChecked');
        					if(row.length>0){
        						if(row.length==1){
        							$.messager.confirm('Confirm','确定要设置吗?设置后本员工下其他主岗将不是主岗',function(r){
            							if(r){
            								$.ajax({
            						            type: "GET",
            						            url: url+"?userId="+row[0].userId+"&orgId="+row[0].orgId+"&jobId="+row[0].jobId,
            						            dataType: "json",
            						            success: function(data){
            						            	if(data.success){
            						            		showSuccessMsg("删除成功");
            						            		loadDataGrid(childGrid);
            						            	}else{
//            						            		$.messager.alert('Warning',data.msg);
            						            		showMsg(data.msg);
            						            	}
            						            }
            						        });
            							}
            						});
        						}else{
        							showInfo("只能设置一个主岗");
        						}
        					}else{
        						showInfo("请选中要设置的行");
        					}
        				})
        			}
        		}
        	});
 			
 			
 			$('#allotjobIdFoot').children("a[type='save']").click(function(){
        		var saveurl=$('#userAllotJobForm').attr("target");
        		//新增窗口保存方法
        		$('#userAllotJobForm').form(
        				'submit',
        				{
        					url : saveurl,
        					onSubmit : function(param) {
        					},
        					success : function(data) {
        						var obj = $.parseJSON(data);
        						if (obj.success) {
        							showSuccessMsg("操作成功！");
        							loadDataGrid(childGrid);
        							closeFun("allotJobId","userAllotJobForm",childGrid)
        						} else {
        							showMsg(obj.msg);
        						}
        					}
        				});
        	});
 			
 			$('#allotjobIdFoot').children("a[type='close']").click(function(){
 				closeFun("allotJobId","userAllotJobForm",childGrid)
 			});
 			
    	 }
    };
    
    
    $.CityRowClick = function (arg) {
    	this.init =function () {
    		 var province=arg.provinceGrid+"_list_id";
    		 var city=arg.cityGrid+"_list_id";
    		 var distrist=arg.distristGrid+"_list_id";
    		 var community=arg.communityGrid+"_list_id";
    		 
 			$('#'+province).datagrid({
 				onClickRow:function(rowIndex,rowData){
 					$('#'+city).datagrid({
						url:arg.url,
						queryParams: {code:rowData.code}
					})
					showMap(rowData.lng,rowData.lat,5);
 				},
 				rowStyler:function(index,row){
 					if(row.code=="110000" || row.code=="120000" || row.code=="310000" || row.code=="500000"){
 						return 'color:red;';
 					}
 				}
 			});
 			
 			$('#'+city).datagrid({
 				onClickRow:function(rowIndex,rowData){
 					$('#'+distrist).datagrid({
						url:arg.url,
						queryParams: {code:rowData.code}
					})
					showMap(rowData.lng,rowData.lat,10);
 				}
 			});
 			
 			$('#'+distrist).datagrid({
 				onClickRow:function(rowIndex,rowData){
 					$('#'+community).datagrid({
						url:arg.url,
						queryParams: {code:rowData.code}
					})
					showMap(rowData.lng,rowData.lat,15);
 				}
 			});
 			
 			$('#'+community).datagrid({
 				onClickRow:function(rowIndex,rowData){
					showMap(rowData.lng,rowData.lat,18);
 				}
 			});
    	}
    };
    
    
    $.genelRowClick = function (arg) {
    	this.init =function () {
    		 var grid=arg.myGrid+"_list_id";
 			$('#'+grid).datagrid({
 				onClickRow:function(rowIndex,rowData){
 					window.location.href=arg.myUrl+rowData.id;
 				}
 			});
    	}
    };
    
    $.dictGrid = function (arg) {
    	//表格加载
        this.gridType=function(){
        	var gridDateId=arg.item+'_list_id';//表格id
        	var gridChild=arg.itemChild+'_list_id';//表格id
        	 $('#'+gridDateId).datagrid({
				 url:arg.typeURL,
				 queryParams: {param:"level_EQ_0",flag:2},
				 onClickRow:function(rowIndex,rowData){
	 					$('#'+gridChild).datagrid({
							url:arg.typeURL,
							queryParams: {param:"level_EQ_1,parent_EQ_"+rowData.id,flag:2}
						})
	 				}
			 }); //指定列;
        };
    };
    
    $.fn.GL = function (options) {
        var dataop = {
            ocolor:'red',
            oshuru:'高亮',
        };
        var chuancan = $.extend(dataop,options);
        $(this).each(function()//先遍历，清除上一次的样式
        {
            var _this = $(this)
            _this.find($(".glnow")).each(function()//找到所有highlight属性的元素；
            {
                $(this).css({color:""});//将他们的属性去掉；
            });
        });
        if(chuancan.oshuru==''){
            return false;
        }else{
            var regExp = new RegExp("(" + chuancan.oshuru.replace(/[(){}.+*?^$|\\\[\]]/g, "\\$&") + ")", "ig");//创建正则表达式，g表示全局的，如果不用g，则查找到第一个就不会继续向下查找了；
            $(this).each(function()//遍历文章；
            {
                var _this1 = $(this)
                var html = _this1.html();
                var newHtml = html.replace(regExp, '<span class="glnow" style="color:'+chuancan.ocolor+'">'+chuancan.oshuru+'</span>');//将找到的关键字替换，加上highlight属性；
                _this1.html(newHtml);//更新文章；
            });
        }
    }
    
})(jQuery);

function showMap(lat,lng,zoom){
	console.log(lat);
	console.log(lng);
	var mapObj = new AMap.Map("amapcity",{
	    center: [lng,lat],
	    zoom:zoom
	});
	var marker = new AMap.Marker({
		position: [lng,lat],
		map:mapObj
	})
}


/**
 * js解析url 并且返回
 * @param url
 * @param id
 * @returns
 */
function parseUrl(url,id){
	var urls=url.split('&');
	for(var i=0,j=urls.length;i<j;i++){
		var str = url.substring(url.indexOf('[')+1,url.indexOf(']'));
		if(str==''){
			return url;
		}
		if(str=='id'){
			url=url.replace('['+str+']',id)
		}else{
			url=url.replace('['+str+']',getAllHidden(str))
		}
	}
	return url;
}

/**
 * js页面控制设置值
 * @param domid
 * @param val
 */
function setInputVal(domid, val) {
	$('#' + domid).textbox('setValue', val);
	$('#' + domid).textbox('setText', val);
}

/**
 * 获取控件值
 * @param domid
 * @returns
 */
function getInputVal(domid){
	return $('#' + domid).textbox('getValue');
}


/**
 * 列表查询按钮清空 
 */
function SearchCleanBtn(obj){
	var parentDiv=$(obj).parent().parent();
	$(parentDiv).children("input[type='text']").each(function(){
		var search_id=$(this).attr("id");
		setInputVal(search_id,"");
	});
	$(parentDiv).children("input[type='combo']").each(function(){
		var search_id=$(this).attr("id");
		$('#'+search_id).combobox('clear');
	});
}

/**
 * 列表查询按钮执行查询
 * @param id
 * @param datagridId
 */
function SearchDoBtn(obj,datagridId){
	var pamrs=new Array();
	
	var parentDiv=$(obj).parent().parent();
	$(parentDiv).children("input[type='text']").each(function(){
		var search_id=$(this).attr("id");
		var item={};
		item.name=$(this).attr('field');
		item.operator=$(this).attr('sqlsep');
		item.value=getInputVal(search_id);
		pamrs.push(item);
	});
	$(parentDiv).children("input[type='combo']").each(function(){
		var searchcom_id=$(this).attr("id");
		var item={};
		item.name=$(this).attr('field');
		item.operator=$(this).attr('sqlsep');
		item.value=$('#'+searchcom_id).combobox("getValue");
		pamrs.push(item);
	});
	$(parentDiv).children("input[type='hidden']").each(function(){
		var item={};
		item.name=$(this).attr('field');
		item.operator=$(this).attr('sqlsep');
		item.value=$(this).val()
		pamrs.push(item);
	});
	var pstr=JSON.stringify(pamrs);
	$('#'+datagridId+'_list_id').datagrid('load',{param:pstr});
	
}

/**
 * 关闭窗口
 * @param windowid
 * @param windowForm
 * @param listid
 */
function closeFun(windowid,windowForm,listid) {
	cleanTable(windowForm,listid);
	$('#'+windowid).window('close');
}

/**
 * 清空表单
 * @param windowForm
 * @param listid
 */
function cleanTable(windowForm,listid){
	$("#"+windowForm).form('clear');
	$("#"+listid).datagrid('clearSelections');
	$('#'+listid).datagrid('unselectAll')
}

/**
 * 默认加载
 * @param grid
 * @param defaultParam
 */
function loadDataGrid(grid,defaultParam){
	var myparam=getParams(defaultParam);
	if(myparam==''){
		$('#'+grid).datagrid('load');
	}else{
		$('#'+grid).datagrid('load',{param:myparam});
	}
	userStyle(grid);
}

function userStyle(grid){
	if(grid=='user_list_id'){
		$('#'+grid).datagrid({
			rowStyler:function(index,row){
				if($('#leader_hidden_id').val()==row.id){
					return 'color:blue;font-weight:bold;';
				}
			 }
		});
	}
}

function reLoadDataGrid(grid,defaultParam){
	var myparam=getParams(defaultParam);
	if(myparam==''){
		$('#'+grid).datagrid('reload');
	}else{
		$('#'+grid).datagrid('reload',{param:myparam});
	}
}


/**
 * 得到指定的参数
 * @param defaultParam
 * @returns
 */
function getParams(defaultParam){
	var myparam=$.trim(defaultParam);
	if(myparam!=''){
		var pamrs=new Array();
		if(myparam.indexOf(",")>-1){
			var params=myparam.split(",");
			for(var i=0;i<params.length;i++){
				var pm=params[i];
				if(pm!=''){
					var fild=$('#'+pm+'_search_id').attr('field');
					if(fild!=''){
						var item={};
						item.name=$('#'+pm+'_search_id').attr('field');
						item.operator=$('#'+pm+'_search_id').attr('sqlsep');
						item.value=$('#'+pm+'_search_id').val();
						pamrs.push(item);
					}
				}
			}
		}else{
			var myfild=$('#'+myparam+'_search_id').attr('field');
			if(myfild!=''){
				var item={};
				item.name=$('#'+myparam+'_search_id').attr('field');
				item.operator=$('#'+myparam+'_search_id').attr('sqlsep');
				item.value=$('#'+myparam+'_search_id').val();
				pamrs.push(item);
			}
		}
		var pstr=JSON.stringify(pamrs);
		return pstr;
	}
	return '';
}

function showSuccessMsg(msg){
	$.message({
        message:msg+'(3秒后关闭)',
        type:'success',
        duration:3000
    });
}

/**
 * 表单保存显示错误提示
 */
function showMsg(msg){
	$.message({
        message:'警告提示:'+msg+'(3秒后关闭)',
        type:'warning',
		duration:3000
	 });
}

/**
 * 表单隐藏错误信息
 */
function showInfo(msg){
	$.message({
        message:'提示:'+msg+'(3秒后关闭)',
        type:'info',
		duration:3000
	 });
}

/**
 * 得到查询条件里面的隐藏域
 * @param id
 * @returns
 */
function getSearchHidden(id){
	return $('#'+id+'_search_id').val();
}
function setSearchHidden(id,val){
	return $('#'+id+'_search_id').val(val);
}

/**
 * 得到普通的隐藏域
 * @param id
 * @returns
 */
function getGenelHidden(id){
	return $('#'+id+'_hidden_id').val();
}
function setGenelHidden(id,val){
	return $('#'+id+'_hidden_id').val(val);
}

function getAllHidden(id){
	var val=getSearchHidden(id);
	if(val==null || val==''){
		val=getGenelHidden(id);
	}
	return val;
}

/**
 * 提交
 * @param url
 * @param mdata
 */
function commitAjax(url,mdata){
 	$.ajax({
         type: "POST",
         url: url,
         contentType: 'application/x-www-form-urlencoded;charset=utf-8',
         data: mdata,
         dataType: "json",
         success: function(data){
        	 showSuccessMsg("提交成功");
         },
         error:function(e){
        	 showMsg(e);
         }
     });
 }


function createCombo(id,url,seleval,text,val){
	$("#"+id).empty();
	$.ajax({
        type: "POST",
        url: url,
        contentType: 'application/x-www-form-urlencoded;charset=utf-8',
        dataType: "json",
        success: function(data){
        	if(data && data.length>0){
        		$("#"+id).empty();
        		$("#"+id).append("<option value=''>--请选择--</option>");
        		$.each(data, function (index, item) {
        			if(seleval==item[''+val+'']){
        				$("#"+id).append("<option  selected='selected' value='"+item[''+val+'']+"'>"+item[''+text+'']+"</option>");
        			}else{
        				$("#"+id).append("<option value='"+item[''+val+'']+"'>"+item[''+text+'']+"</option>");
        			}
        		})
        	}
        },
        error:function(e){
        	
        }
    });
}


function createRadio(id,name,url,seleval,text,val){
	$("#"+id).empty();
	$.ajax({
        type: "POST",
        url: url,
        contentType: 'application/x-www-form-urlencoded;charset=utf-8',
        dataType: "json",
        success: function(data){
        	if(data && data.length>0){
        		$("#"+id).empty();
        		$.each(data, function (index, item) {
        			if(seleval==item[''+val+'']){
        				$("#"+id).append("<input class='easyui-radio' type='radio' checked='checked'  name='"+name+"' value='"+item[''+val+'']+"'/>"+item[''+text+'']);
        			}else{
        				$("#"+id).append("<input class='easyui-radio' type='radio'  name='"+name+"' value='"+item[''+val+'']+"'/>"+item[''+text+'']);
        			}
        		})
        	}
        },
        error:function(e){
        	
        }
    });
}
function createGridById(grid,url){
	$.ajax({
        type: "POST",
        url: url,
        contentType: 'application/x-www-form-urlencoded;charset=utf-8',
        dataType: "json",
        success: function(data){
        	 var obj=$('#'+grid)
        	var rows={};
        	if(data && data.length>0){
        		rows.list=data;
        		rows.size=true;
        	}else{
        		rows.list=[];
        		rows.size=false;
        	}
        	var html= template("tpl-setting", rows);
        	 $(obj).empty();
             $(obj).html(html);
        },
        error:function(e){
        	
        }
    });
}


function isNumber(value) { 
	var patrn = /^(-)?\d+(\.\d+)?$/;
	if (patrn.exec(value) == null || value == "") {
		 return false;
	}
	return true;
}

function openGenelWindow(winid,url){
	$('#'+winid).window('open');
	$('#'+winid).window('refresh',url);
}


function Open(text, url ,icons) {
  if ($("#system_tab_id").tabs('exists', text)) {
      $('#system_tab_id').tabs('select', text);
  } else {
      $('#system_tab_id').tabs('add', {
          title : text,
          iconCls : icons,
          closable : true,
          content : '<iframe scrolling="no" frameborder="0" marginheight="0" marginwidth="0"   src="'+url+'" style="width:100%;height:99%;margin:0px 0px;"></iframe>'
      });
  }
}